/**
 * 
 */
package controllers;

import java.util.ArrayList;
import java.util.List;

import client.gui.panels.PanelIF;
import client.gui.panels.TimeFrameRequest;
import entities.Message;
import entities.MsgType;
import entities.ObjectType;
import entities.Ticket;

/**
 * @author Vodi
 *
 */
public class TimeFrameRequestController implements ControllerIF {
	
	/**
	 * the time frame approval panel
	 */
	private TimeFrameRequest timeFrameRequestPanel;

	/**
	 * reference of the hosting panel's controller
	 */
	private ViewTicketController hostController;
	
	/**
	 * String holding the current ticket's state
	 */
	private Ticket ticket;
	
	/**
	 * the time duration requested by the evaluator
	 */
	private Integer requestedTime;
	
	
	public TimeFrameRequestController(ControllerIF hostController, Ticket ticket) {
		this.hostController = (ViewTicketController) hostController;
		this.ticket = ticket;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#getPanel()
	 */
	@Override
	public PanelIF getPanel() {
		return timeFrameRequestPanel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#setPanel(client.gui.panels.PanelIF)
	 */
	@Override
	public void setPanel(PanelIF panel) {
		timeFrameRequestPanel = (TimeFrameRequest) panel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#action()
	 */
	@Override
	public void action() {
		List<String> details = new ArrayList<>();
		MsgType msgType = null;
		this.requestedTime = timeFrameRequestPanel.getEvaluatorRequest();
		
		if(ticket.equals("EVALUATION_DURATION")) {
			msgType = MsgType.SET_EVALUATION_DURATION_REQUEST;
		}
		else if(ticket.equals("EXECUTION_DURATION")) {
			msgType = MsgType.SET_EXECUTION_DURATION_REQUEST;
		}
		
		details.add(ticket.getTicket_id().toString());
		details.add(timeFrameRequestPanel.getEvaluatorRequest().toString());
		Message message = new Message(msgType, ObjectType.MIX_ARRAY, details);
		hostController.sendMessage(message);
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#decipherMessage(entities.Message)
	 */
	@Override
	public void decipherMessage(Message message) {}

}
